package com.rd.student.dashuju.zhengchengxiang.Day0807;


import java.io.*;
import java.util.ArrayList;
import java.util.Collections;

public class GrandLotto {
    public static void main(String[] args) throws Exception {
        // 35个号码
        ArrayList<String> list1 = new ArrayList<>();
        for (int i = 1; i <= 35; i++) {
            if (i < 10) {
                list1.add("0" + i);
            } else {
                list1.add("" + i);
            }


        }
        ArrayList<String> list2 = new ArrayList<>();
        for (int i = 1; i <= 12; i++) {
            if (i < 10) {
                list2.add("0" + i);
            } else {
                list2.add("" + i);
            }
        }

        // 打乱
        Collections.shuffle(list1);
        Collections.shuffle(list2);

        // 中奖号码
        StringBuilder winStr = new StringBuilder();
        for (int i = 0; i < 5; i++) {
            winStr.append(list1.get(i) + " ");
        }
        winStr.append("| ");
        for (int i = 0; i < 2; i++) {
            winStr.append(list2.get(i) + " ");
        }

        // 存储中奖号码到daletou.txt
        Writer winBriter = new FileWriter(new File("daletou.txt"));
        winBriter.write(winStr.toString());
        winBriter.close();


        StringBuilder buyStr = new StringBuilder();
        int number = 1000000;
        for (int i = 0; i < number; i++) {
            // 打乱number次
            Collections.shuffle(list1);
            Collections.shuffle(list2);

            for (int j1 = 0; j1 < 5; j1++) {
                buyStr.append(list1.get(j1) + " ");
            }
            buyStr.append("| ");
            for (int j2 = 0; j2 < 2; j2++) {
                buyStr.append(list2.get(j2) + " ");
            }
            buyStr.append("\n");
        }
        // 存储购买号码到randomDLT.txt
        Writer buyWriter = new FileWriter(new File("randomDLT.txt"));
        buyWriter.write(buyStr.toString());
        buyWriter.close();

        // 读取中奖号码 和 购买号码
        BufferedReader winReader = new BufferedReader(new FileReader("daletou.txt"));
        BufferedReader buyReader = new BufferedReader(new FileReader("randomDLT.txt"));
        // 一次读取的长度
        ArrayList<String> winList = new ArrayList<>();
        ArrayList<String> buyList = new ArrayList<>();
        String winLine = null;
        while (true) {
            winLine = winReader.readLine();
            if (winLine == null) break;
            winList.add(winLine);
        }
        String buyLine = null;
        while (true) {
            buyLine = buyReader.readLine();
            if (buyLine == null) break;
            buyList.add(buyLine);
        }

        // 将中奖的个数存储到到文件 num.txt 中
        Writer jackpotWriter = new FileWriter(new File("num.txt"));
        // 匹配是否中奖
        for (int i = 0; i < buyList.size(); i++) {
            if (buyList.get(i).contains(winList.get(0))) {
                System.out.println("中奖了");
                jackpotWriter.write(buyList.get(i));
            } else {
                System.out.println((i + 1) + "-没中奖");
            }
        }

        jackpotWriter.close();
        buyReader.close();
        winReader.close();

    }
}
